import 'package:date_format/date_format.dart';

import '../generated/l10n.dart' as language;

class TimeUtils {
  static String gtTime(DateTime _nowDate) {
    //// 获取当前时间戳
    //print(_nowDate.millisecondsSinceEpoch);
    return formatDate(_nowDate, [
      mm,
      language.S.current.month_,
      yyyy,
      language.S.current.year_,
    ]);
  }

//获取当前日期的月份
  static int CurrentMonth() {
    return DateTime.now().month - 1;
  }

  static String gtTime3() {
    //// 获取当前时间戳
    //print(_nowDate.millisecondsSinceEpoch);

    return formatDate(DateTime.now(), [
      mm,
      language.S.current.month_,
      yyyy,
      language.S.current.year_,
    ]);
  }

  static String gtTime4(DateTime _nowDate) {
    //// 获取当前时间戳
    //print(_nowDate.millisecondsSinceEpoch);

    return formatDate(_nowDate, [
      dd,
      "-",
      mm,
      "-",
      yyyy,
      " ",
      HH,
      ":",
      nn,
      ":",
      ss,
    ]);
  }

  static String gtTime2(DateTime _nowDate) {
    //// 获取当前时间戳
    //print(_nowDate.millisecondsSinceEpoch);

    return formatDate(_nowDate, [
        mm,
      language.S.current.month_,
      dd,
      language.S.current.day_," ",
      yyyy,
      language.S.current.year_,
    ]);
  }

 static String gtTime6(DateTime _nowDate) {
    //// 获取当前时间戳
    //print(_nowDate.millisecondsSinceEpoch);

    return formatDate(_nowDate, [
      dd,
      '-',
      mm,
      '-',
      yyyy,
    ]);
  }

   static String gtTime7(DateTime _nowDate) {
    //// 获取当前时间戳
    //print(_nowDate.millisecondsSinceEpoch);
    return formatDate(_nowDate, [
      yyyy,
    ]);
  }


/**
 * 比较时间是否在本周内  北京时间的话应该比实际多减8个小时才正确 比如想得到时间为2022-09-25 12:00:00 就必须传 2022-09-25 20:00:00
 */
  static bool IsBetweenOneWeek(
    int dt1,
  ) {
    DateTime now = DateTime.now();
    //周一算第一天。外国是周末，所以这里需要减-1；
    int daysOfWeek = now.weekday - 1;
    //本周的周一。19-09-2022 00:00:00
    DateTime firstDay = DateTime(now.year, now.month, now.day - daysOfWeek);
    //本周的周日
    DateTime lastDay = firstDay
        .add(Duration(days: 6, hours: 23, minutes: 59, seconds: 59)); //23:59:59
    //.  print("本周的周一开始时间:${gtTime4(firstDay)}");
    // print("本周的周日结束时间:${gtTime4(lastDay)}");
    // print("是按成都市${ lastDay.millisecondsSinceEpoch}");
    //  var dateTime = DateTime.fromMillisecondsSinceEpoch(lastDay.millisecondsSinceEpoch);
    //  print("转换后${gtTime4(dateTime)}");

    var dateTime = DateTime.fromMillisecondsSinceEpoch(dt1);
    //  print("传入的时间是${gtTime4(dateTime)}");

    if (dateTime.isAfter(firstDay) && dateTime.isBefore(lastDay)) {
      //如果指定时间在本周一的后面 且 在本周末的前面
     // print("是否在同一周:true");
      return true;
    } else {
      print("是否在同一周:false");
      return false;
    }
    //另外的方法 https://www.jianshu.com/p/5e1177f000e7

    //millisecondsSinceEpoch
    // if (firstDay.millisecondsSinceEpoch <= dt1 &&
    //     dt1 <= lastDay.millisecondsSinceEpoch) {
    //    return true;
    // } else {
    //   return false;
    // }

    //下周的周一。。26-09-2022 00:00:00
    //   DateTime nextFirst = firstDay.add(Duration(days: 7));
//下周的周日 02-10-2022 23:59:00
    // DateTime nextLast = lastDay.add(Duration(days: 7));

    //  print(gtTime4(nextFirst));
    // print(gtTime4(nextLast));
    //上周的周一12-09-2022 00:00:00
    //  DateTime prevFirst = firstDay.subtract(Duration(days: 7));
    //上周的周末 18-09-2022 23:59:00
    // DateTime prevLast = lastDay.subtract(Duration(days: 7));

    // print(gtTime4(prevFirst));
    //  print(gtTime4(prevLast));
  }
}
